/* -*- c++ -*- */
/*
 * Copyright 2022 Analog Devices Inc..
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#ifndef INCLUDED_M2K_ANALOG_IN_SOURCE_H
#define INCLUDED_M2K_ANALOG_IN_SOURCE_H

#include <gnuradio/m2k/api.h>
#include <gnuradio/sync_block.h>
#include <libm2k/m2k.hpp>

namespace gr {
  namespace m2k {


  /*!
   * \brief Source for ADALM2000 with buffered output channels
   * \ingroup m2k
   *
   * \details
   * This block allows for streaming data from ADALM2000
   */
  class M2K_API analog_in_source : virtual public gr::sync_block {
  public:
	  typedef std::shared_ptr <analog_in_source> sptr;

	  /*!
	   * \brief Return a shared_ptr to a new instance of m2k::analog_in_source.
	   *
	   * \param uri String of the context uri
	   * \param buffer_size Integer number of samples to be put into each buffered
	   * \param channels List of channel's states (enable/disable)
	   * \param ranges List of ranges for the given channels
	   * \param sampling_frequency Frequency at which the hardware will input samples
	   * \param oversampling_ratio Integer number representing the oversampling factor
	   * \param kernel_buffers The number of the internal buffers
	   * \param calibrate_ADC Boolean value for deciding if the ADC should be calibrated
	   * \param stream_voltage_values Boolean value for setting the output type: voltage/raw
	   * \param trigger_condition List of triggering conditions for the given channels
	   * \param trigger_mode List of triggering modes for the given channels
	   * \param trigger_source The source for the triggering event
	   * \param trigger_delay The number of samples in buffer before the triggered sample
	   * \param streaming configures m2k in streaming mode
	   * \param deinit clears m2k resources on deinit - useful when used in conjunction with other software that handles deinit
	   * \param data_rate sets a data rate of data_rate buffers per second
	   */
	  static sptr make(const std::string &uri,
					   int buffer_size,
					   const std::vector<int> &channels,
					   std::vector<int> ranges,
					   double sampling_frequency,
					   int oversampling_ratio,
					   int kernel_buffers,
					   bool calibrate_ADC,
					   bool stream_voltage_values,
					   std::vector<int> trigger_condition,
					   std::vector<int> trigger_mode,
					   int trigger_source,
					   int trigger_delay,
					   std::vector<double> trigger_level,
					   bool streaming,
					   bool deinit = true,
					   double data_rate = 0);

	  static sptr make_from(libm2k::context::M2k *context,
						    int buffer_size,
						    const std::vector<int> &channels,
						    std::vector<int> ranges,
						    double sampling_frequency,
						    int oversampling_ratio,
						    int kernel_buffers,
						    bool calibrate_ADC,
						    bool stream_voltage_values,
						    std::vector<int> trigger_condition,
						    std::vector<int> trigger_mode,
						    int trigger_source,
						    int trigger_delay,
						    std::vector<double> trigger_level,
						    bool streaming,
						    bool deinit = true,
						    double data_rate = 0);

	  virtual void set_params(std::vector<int> ranges,
							  double sampling_frequency,
							  int oversampling_ratio) = 0;

	  virtual void set_data_rate(double rate) = 0;

	  virtual void set_trigger(std::vector<int> trigger_condition,
							   std::vector<int> trigger_mode,
							   int trigger_source,
							   int trigger_delay,
							   std::vector<double> trigger_level,
							   bool streaming) = 0;

	  virtual void set_timeout_ms(unsigned int timeout) = 0;

	  virtual void set_buffer_size(int buffer_size) = 0;

  };

  } // namespace m2k
} // namespace gr

#endif /* INCLUDED_M2K_ANALOG_IN_SOURCE_H */
